The present invention relates generally to computer graphics and, more particularly, to a method and apparatus for improved texture mapping for three-dimensional computer graphics.
In the art of computers, two-dimensional and three-dimensional images are commonly depicted on a display, i.e. computer monitor, with a system including a central processing unit (CPU) that is connected to the display via a video card or the like. The display consists of a large number of pixels(picture elements) which each display a small portion of an image in response to video control signals received from the CPU. These video signals are conventionally manipulated by the video card in order to enhance images depicted on the display.
In particular, video signals received from a CPU typically include information in the form of a predetermined number of bits which are allocated to different components of the pixel with which it is associated. Such components include a Red (R), Green (G), Blue (B), and Alpha (xcex1) component. While the R, G, and B components relate to the intensity of the corresponding color within the pixel, the xcex1 component may correspond to various types of information depending on the specific representation that is being employed.
In one representation, the xcex1 component corresponds to a xe2x80x9ctransparencyxe2x80x9d or xe2x80x9copacityxe2x80x9d of the colors within the associated pixel. In such representation, the xcex1 component is commonly used for blending purposes. In yet another representation, the xcex1 component stores information relating to xe2x80x9ccoveragexe2x80x9d for determining a fraction of how much color is present within the associated pixel. In all of the representations, the xcex1 component of the video signals contributes additional information for improving the resultant image.
It should be noted that the amount and allocation of binary information within the various R, G, B, and xcex1 components may vary depending on the particular application. In one example wherein 16 bits are provided for each pixel, the R, G, B, and xcex1 components may be allocated 5, 6, 5, and 0 bits, respectively, or, in another embodiment, 5, 5, 5, and 1 bits, respectively. In yet another example wherein each pixel has 32 allocated bits, each component (R, G, B, and xcex1) may have 8 bits associated therewith.
With the number of bits allocated for each pixel, information stored therein may be used to generate the resultant image. FIG. 1 illustrates a pixel 10 corresponding to a small portion of an image 12 on a display 13. In order to provide a more realistic image, the R, G, and B components of the pixel are desired to accurately reflect a specific texture and lighting. As seen in FIG. 1A, this texture and lighting information is usually gathered from a texture pattern grid 14 stored in computer memory in a process conventionally referred to as texture mapping. During texture mapping, information associated with a pixel, or xe2x80x9ctexelxe2x80x9d 16, from the texture pattern grid 14 stored in computer memory is selected and incorporated into the appropriate pixel 10 within the image 12. As will be set forth later, this texture mapping may be accomplished in various ways depending on the xe2x80x9crepresentationxe2x80x9d of the R, G, B, and xcex1 components of the video signals.
For example, xe2x80x9cpremultipliedxe2x80x9d, xe2x80x9cpostmultipliedxe2x80x9d, and xe2x80x9ccolorkeyedxe2x80x9d are all different types of representations of the R, G, B, and xcex1 components of the video signals. The premultiplied representation refers to modulating the R, G, and B components with the xcex1 component in order to weight the R, G, and B components prior to further processing. In other words, the information associated with the xcex1 component is incorporated into the R, G, and B components before any further processing, i.e. filtering, etc. As will soon become apparent, such premultiplication of the components is critical for improving picture quality by way of interpolation.
A specific example of the foregoing texture mapping procedure is shown in FIG. 1B. As shown, the image to be mapped is referred to as a texture map 20, and its individual elements are referred to as texels. Texture map 20 is typically described in a rectangular coordinate scheme designated (u, v), and is ordinarily stored in some area of conventional memory, such as, for example, a conventional page-mode dynamic random-access memory (DRAM) or other paged memory. In the example of FIG. 1B, four pages 22, 24, 26, 28 are shown, each corresponding to a portion of the image area containing a corresponding portion of texture map 20.
Surface 30 in three-dimensional space has its own coordinate system (s,t,q). In a typical three-dimensional graphics system, surface 30 may be a primitive object such as a polygon; many such polygons may be defined in three-space to form a three-dimensional object or scene. Each such polygon would be placed in the coordinate system (s,t,q) similar to the surface 30 in FIG. 1B. Based on the orientation of surface 30 in three dimensions, and on the position and orientation of the xe2x80x9ccamera,xe2x80x9d surface 30 is in turn mapped onto a two-dimensional display grid 40 stored in a frame buffer for display by the computer.
The mapping of surface 30 onto display grid 40 is accomplished by matrix transforms that are well-known in the art. Display grid 40 has coordinate system (x, y) and is typically implemented in an area of memory reserved for video display, such as video random-access memory (video RAM) e.g. VRAM or synchronous graphics random-access memory (SGRAM).
Display grid 40 contains individual elements known as pixels, represented by distinct memory locations in video RAM. Each pixel in some region of display grid 40 maps onto a point on surface 30 and in turn to a point in texture map 20. Thus, in the example of FIG. 1B, point Axy of display grid 40 maps onto point Astq in the coordinates of surface 30 and to point Auv in texture map 20, or a group of points forming a region in texture map 20. Each of the mappings among display grid 40, surface 30, and texture map 20 may be point-to-point, point-to-region, region-to-point, or region-to-region.
In order to improve picture quality during texture mapping, it is often desired to interpolate between the various texels of the texture pattern grid in order to select the best texture and lighting information that is to be depicted within the pixel of the image. It is important to note that this interpolation, or bilinear interpolation, is permitted only when the various components of the video signals are weighted in the premultiplied representation. Without premultiplication, interpolation of the components of the video signals results in errors and artifacts.
A flowchart depicting the process associated with texture mapping in the premultiplied representation is shown in FIG. 2. During bilinear interpolation, four texels are first selected (see FIG. 3) and the interpolation is subsequently carried out between them for each of the R, G, and B components. With reference to the four selected texels A, B, C, and D of FIG. 3, the interpolation proceeds as follows for each of the R, G, and B components:
AB=A(1xe2x88x92x)+B(x)
CD=C(1xe2x88x92x)+D(x)
(R,G,B)=AB(1xe2x88x92y)+CD(y)
Interpolation between the texels affords a xe2x80x9csmootherxe2x80x9d more realistic resultant image on the display. It should be noted that interpolation need not be limited to merely two dimensions. Three-dimensional interpolation, or trilinear interpolation, may also be carried out. More information on trilinear interpolation may be found by looking to xe2x80x9cPyramidal Parametricsxe2x80x9d by Williams, Lance. In Proceedings of SIGGRAPH ""83 (July 1983), pp. 1-11 which is incorporated herein by reference in its entirety.
As mentioned earlier, interpolation during texture mapping is not effective when the various components of the video signals take on the postmultiplied and colorkeyed representations. Instead, in the case of postmultiplied representation, the R, G, and B components are first interpolated, then modulated, or multiplied, with the xcex1 component. This process is delineated FIG. 4A. In the case of the colorkeyed representation, texels that match the colorkey have their xcex1 component set to zero. This process is delineated in FIG. 4B.
In operation, video cards are often required to process each of the aforementioned types of pixel component representations. This mixture of the various pixel component representations in texture mapping brings rise to inconsistencies that in turn lead to difficulties in processing the video signals. In particular, such inconsistencies prompt the need for constraints which translate into additional processing that, in the end, result in reduced image quality.
There is thus a need for a processing technique that is capable of distinguishing between and handling multiple types of R, G, B, and xcex1 component representations.
A method and apparatus is provided for processing multiple types of pixel component representations. The method of the present invention first includes identifying a plurality of texels in a texture pattern grid that correspond to a pixel. Thereafter, there are two orthogonal states: colorkeyed or not, and premultiplied or not. These two states give four modes of operation. In the first mode, the texels are not colorkeyed but are premultiplied; in this mode, the color components are passed unmodified to the interpolator. In the second mode, the texels are not colorkeyed and not premultiplied; in this mode, the color components are multiplied by alpha before being passed to the interpolator. In the third mode, the texels are colorkeyed and are premultiplied; in this mode, for texels that match the colorkey, the color and alpha components are all set to zero, then passed to the interpolator. Texels that do not match the colorkey are unmodified. In the fourth mode, the texels are colorkeyed and not premultiplied; in this mode, for texels that match the colorkey, the color and alpha components are all set to zero. Following that, the color components are multiplied by alpha, then sent to the interpolator.
Next, a position is interpolated on the texture pattern grid between the texels that corresponds to the pixel. Finally, the information components of the pixel are filtered.
By this feature, the present invention ensures that the information components are in the premultiplied representation. As such, the benefits of interpolation may be accrued during texture mapping regardless of the type of component representation received.